package com.myt.matp.utils;

import java.util.*;

public final class Util {

    /**
     * Describe <code>findChar</code> method here.
     *
     * Searches the array for the character c. Returns a value
     * major or equal to 0 and minor that chars.length in sucessfull
     * case. Otherwise, return -1.
      *
     * @param c a <code>char</code> value
     * @param chars a <code>char</code> value
     * @param start an <code>int</code> value
     * @param length an <code>int</code> value
     * @return an <code>int</code> value
     */
    public static int findChar(char c, char chars[], int start, int length) {
	int ret = -1;
	for (int i = start; i < length; i++) {
	    if (chars[i] == c) {
		ret = i;
		break;
	    }
	}
	return ret;
    }

    public static int findChar(char c, char chars[], int start) {
	return findChar(c, chars, start, chars.length - start);
    }

    public static int findChar(char c, char chars[]) {
	return findChar(c, chars, 0);
    }

    public static int computeMCD(int x, int y) {
        // Algoritmo simple
        int t;
        x = Math.abs(x);
        y = Math.abs(y);
        t = Math.min(x, y);
        while ( (x % t != 0) || (y % t != 0)) {
            --t;
        }
        return t;
	// Algoritmo recursivo (Euclides) mas eficiente para numeros grandes
        // return (!y) ? x : calcMCD(y,x%y);
    }

}
